//
//  StartScene.m
//  iAnimator
//
//  Created by 국현 경 on 09. 06. 01.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "StartScene.h"
#import "MenuScene.h"

@implementation StartScene
- (id) init {
	
    self = [super init];
    if (self != nil) {
       
        [self addChild:[GameLayer node] z:1];
    }
    return self;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *touch = [touches anyObject];
	CGPoint location = [touch locationInView: [touch view]];

	NSLog(@"1Touch began %f", location.x);
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
	CGPoint location = [touch locationInView: [touch view]];
    [self doWhateverYouWantToDo];
    [self doItWithATouch:touch];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
	CGPoint location = [touch locationInView: [touch view]];
    [self doWhateverYouWantToDo];
    [self doItWithATouch:touch];
}
@end

@implementation GameLayer
- (id) init {
    self = [super init];
    if (self != nil) {
        isTouchEnabled = YES;
		testImage = [Sprite spriteWithFile:@"game.png"];
        [testImage setPosition:ccp(240, 160)];
        [self addChild:testImage z:0];
    }
    return self;
}

-(BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *touch = [touches anyObject];
	CGPoint location = [touch locationInView: [touch view]];
	
	NSLog(@"2Touch began %f, %f", location.x, location.y);
    return kEventHandled;
}

- (BOOL)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *touch = [touches anyObject];
	CGPoint location = [touch locationInView: [touch view]];
	
	// 좌표 변환
	location = CGPointMake(location.y, location.x);
	
	// 이미지 이동
	[testImage setPosition:location];
	
	//CocosNode *line = drawLine(10.0f, 100.0f,400.0f,27.0f);
	//[self addChild:line z:2];
	NSLog(@"2Touch moved %f, %f", location.x, location.y);
	return kEventHandled;
}


- (BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *touch = [touches anyObject];
	CGPoint location = [touch locationInView: [touch view]];
	
	NSLog(@"2Touch ended %f, %f", location.x, location.y);
	
//	[[Director sharedDirector] popScene];
    //MenuScene * ms = [MenuScene node];
    //[[Director sharedDirector] replaceScene:ms];
    return kEventHandled;
}
@end
